﻿ @{
    ViewBag.Title = "WarehouseInfoIndex";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}@using LeSoft.Application.Code;
<script>
    var _organizeid = "@OperatorProvider.Provider.Current().CompanyId", _pstructId = "", _WarehouseType = "", _ProductType = "";
    $(function () {
        InitialPage();
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        //layout布局

        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 165.5);
            }, 200);
            e.stopPropagation();
        });
    }

    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        var queryJson = {
            condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
            keyword: $("#txt_Keyword").val()
        };
        $gridTable.jqGrid({
            url: "../../ResourceManage/RS_Warehouse/GetTreeListJson",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 141,
            autowidth: true,           
            colModel: [
                { label: "主键", name: "Id", hidden: true },
                { label: "所属机构", name: "OrganizeId", index: "OrganizeId", width: 250, align: "center", sortable: false },
                { label: "仓库名称", name: "Name", index: "Name", width: 150, align: "center", sortable: false },
                { label: "仓库编号", name: "Code", index: "Code", width: 150, align: "center", sortable: false },
                { label: "所在区域", name: "PStructId", index: "PStructId", width: 150, align: "center", sortable: false },
                { label: "仓库位置", name: "PSMemo", index: "PSMemo", width: 150, align: "center", sortable: false },                
                {
                    label: "有效", name: "EnabledMark", index: "EnabledMark", width: 50, align: "center",
                    formatter: function (cellvalue) {
                        return cellvalue == 1 ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                    }
                },
                { label: "描述", name: "Description", index: "Description", width: 100, align: "center", sortable: false },

            ],
          
            treeGrid: true,
            treeGridModel: "nested",
            ExpandColumn: "Name",
            rowNum: "all",
            rownumbers: true,           
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);

            }
        });
        //查询条件
        $("#queryCondition .dropdown-menu li").click(function () {
            var text = $(this).find('a').html();
            var value = $(this).find('a').attr('data-value');
            $("#queryCondition .dropdown-text").html(text).attr('data-value', value)
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = {
                condition: $("#queryCondition").find('.dropdown-text').attr('data-value'),
                keyword: $("#txt_Keyword").val()

            };
            $gridTable.jqGrid('setGridParam', {
                url: "../../ResourceManage/RS_Warehouse/GetTreeListJson",
                postData: { queryJson: JSON.stringify(queryJson) }
            }).trigger('reloadGrid');
        });


    }

    //新建仓库
    function btn_add() {
        dialogOpen({
            id: "WarehouseInfoForm",
            title: '新建仓库',
            url: '/ResourceManage/RS_Warehouse/Form',
            width: "500px",
            height: "400px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
               
            }

        });
    }
    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "WarehouseInfoForm",
                title: '修改仓库信息',
                url: '/ResourceManage/RS_Warehouse/Form?keyValue=' + keyValue,
                width: "500px",
                height: "400px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                    
                }
            })

        }
    }
    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                url: '/ResourceManage/RS_Warehouse/RemoveForm',
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").resetSelection();
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的数据项！', 0);
        }
    }
</script>

    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td style="padding-left: 2px;">
                                <div class="btn-group" id="queryCondition">
                                    <a class="btn btn-default dropdown-text" data-toggle="dropdown">筛选条件</a>
                                    <a class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a data-value="Code">编号</a></li>
                                        <li><a data-value="Name">名称</a></li>
                                        <li><a data-value="PSMemo">位置</a></li>
                                    </ul>
                                </div>
                            </td>
                            <td style="padding-left: 2px;">
                                <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload(); "><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    </div>

                </div>
            </div>

            <div class="gridPanel">
                <table id="gridTable"></table> 
            </div>
        </div>
    </div>

 